﻿using System;
using System.EnterpriseServices;
using AB.ServiceDirectory.Entities;
using NUnit.Framework;

namespace AB.ServiceDirectory.TestScripts
{
    [TestFixture]
   public class AContactTestBO
    {
        private string _sortType;
        private int _startRowIndex;
        private int _maxRows;

        [SetUp]
        protected  void SetUp()
        {
            _sortType = "ContactId";
            _startRowIndex = 0;
            _maxRows = 15;
            //transaxtiopn
            Console.WriteLine("Attempting to enter a transactional context...");
            var config = new ServiceConfig();
            config.Transaction = TransactionOption.RequiresNew;
            ServiceDomain.Enter(config);
            Console.WriteLine("Attempt suceeded!");
        }
        /// <summary>
        /// Loads all contact_ check exist record_ ouput record.
        /// </summary>
        ///  [Test]
        //AddContact true
        [Test]
        public void TestContact_IncludeActiveTrue_ReturnCollection()
        {
            var filter = new Commons.DataFilters.AContactFilter();
            filter.IncludeInactive = true;
            var actual = BO.AContactBO.GetList(filter, _sortType, _startRowIndex, _maxRows);
            Assert.IsNotNull(actual);

        }
        /// <summary>
        /// Tests the supporting material_ include active false_ return collection.
        /// </summary>
        [Test]
        public void TestContact_IncludeActiveFalse_ReturnCollection()
        {
            var filter = new Commons.DataFilters.AContactFilter();
            filter.IncludeInactive = false;
            var actual = BO.AContactBO.GetList(filter, _sortType, _startRowIndex, _maxRows);
            Assert.IsNotNull(actual);

        }
        [Test]
        public void AddContact_InputValid_OuputTrue()
        {
            Contact contact = new Contact();
            contact.FirstName = "fpt";
            contact.ManageId = 1;
            contact.Surname = "caugiay";
            contact.ContactTypeId = 1;
            contact.KnownAs = "abc";
            contact.BestContactMethodId = 1;
            contact.OfficePhone = "0988332343";
            contact.JobRole = "hehe";
            contact.MobilePhone = "0433343433";
            contact.WorkBase = "Ha noi";
            contact.HomePhone = "0439999999";
            contact.JobTitle = "manage";
            contact.Email = "anhtt17@gmail.com.vn";
            contact.IsActive = true;
            bool actual = BO.AContactBO.AddContact(contact);
            bool expected = true;
            Assert.AreEqual(actual, expected);
        }
        [Test]
        //AddContact False
        public void AddContact_InputNotValid_OuputFalse()
        {

            Contact contact = new Contact();
            contact.FirstName = "";
            contact.ManageId = 1;
            contact.Surname = "";
            contact.ContactTypeId = -1;
            contact.KnownAs = "abc";
            contact.BestContactMethodId = 1;
            contact.OfficePhone = "0988332343";
            contact.JobRole = "hehe";
            contact.MobilePhone = "0433343433";
            contact.WorkBase = "Ha noi";
            contact.HomePhone = "0439999999";
            contact.JobTitle = "manager";
            contact.Email = "anhtt12@gmail.com.vn";
            contact.IsActive = true;
            bool actual = BO.AContactBO.AddContact(contact);
            bool expected = false;
            Assert.AreEqual(actual, expected);
        }
  
        [Test]
        //Edit Contact true
        public void EditContact_InputValid_OuputTrue()
        {
            Contact contact = BO.AContactBO.FindContactById(4);
            contact.ContactId = 4;
            contact.FirstName = "Darla11111";
            contact.ManageId = 64;
            contact.Surname = "Preston";
            contact.ContactTypeId = 2;
            contact.KnownAs = "LSWQ43";
            contact.BestContactMethodId = 6;
            contact.OfficePhone = "866011-5290";
            contact.JobRole = "OMAZ8NDAFHHP373KTAYIZPGDQMZMRWZ8NGPICRZIHEL";
            contact.MobilePhone = "167583-6508";
            contact.WorkBase = "POXSPFI1";
            contact.HomePhone = "568-9557916";
            contact.JobTitle = "Mr";
            contact.Email = "lbrvyjy.yglwkvq@asisvqxrm.oyspxe.org";
            contact.IsActive = false;
            bool actual = BO.AContactBO.EditContact(contact);
            bool expected = true;
            Assert.AreEqual(actual, expected);
        }
        [Test]
        // edit Contact False
        public void EditContact_InputNotValid_OuputFalse()
        {
            Contact contact = new Contact();
            contact.FirstName = "";
            contact.ManageId = 1;
            contact.Surname = "";
            contact.ContactTypeId = 0;
            contact.KnownAs = "";
            contact.BestContactMethodId = 1;
            contact.OfficePhone = "0988332343";
            contact.JobRole = "hehe";
            contact.MobilePhone = "0433343433";
            contact.WorkBase = "Ha noi";
            contact.HomePhone = "0439999999";
            contact.JobTitle = "manager";
            contact.Email = "anhtt15@gmail.com.vn";
            contact.IsActive = true;
            bool actual = BO.AContactBO.EditContact(contact);
            bool expected = false;
            Assert.AreEqual(actual, expected);
        }

       [Test]
       public void LoadAllContact_CheckExistRecord_OuputRecord()
       {
            int actual = BO.AContactBO.FindAllContacts().Count;
            int expected = 0;
            Assert.Greater(actual,expected);

       }
       /// <summary>
       /// Loads all contact_ check not exist record_ output null record.
       /// </summary>
        [Test]
        public void LoadAllContact_CheckNotExistRecord_OutputNullRecord()
        {
            int actual = BO.AContactBO.FindAllContacts().Count;
            int expected = 0;
            Assert.AreNotEqual(actual,expected);

        }
        /// <summary>
        /// Contacts the first name of the follow first name surname_ input firt name_ output follow.
        /// </summary>
        [Test]
        //TH:input FirstName not Surname
        public  void ContactFollowFirstNameSurname_InputFirtName_OutputFollowFirstName()
        {
            string firstName = "Lydia";
            string surname = "";
            int actual = BO.AContactBO.SearchContact(firstName, surname).Count;
            int expected = 0;
            Assert.Greater(actual,expected);

        }
        /// <summary>
        /// Contacts the follow first name surname_ input firt name sur name null_ output all contact.
        /// </summary>
        [Test]
        //TH: Not Input FirstName, Surname
        public void ContactFollowFirstNameSurname_InputFirtNameSurNameNull_OutputAllContact()
        {
            string firstName = "";
            string surname = "";
            int actual = BO.AContactBO.SearchContact(firstName, surname).Count;
            int expected = 0;
            Assert.Greater(actual, expected);

        }
        /// <summary>
        /// Contacts the follow first name surname_ input sur name_ output all contact.
        /// </summary>
        [Test]
        //Th: Input SurName not FirstName
        public void ContactFollowFirstNameSurname_InputSurName_OutputAllContact()
        {
            string firstName = "";
            string surname = "Marc";
            int actual = BO.AContactBO.SearchContact(firstName, surname).Count;
            int expected = 0;
            Assert.Greater(actual, expected);

        }
        /// <summary>
        /// Contacts the follow first name surname_ input surname not exist_ output null.
        /// </summary>
        [Test]
        //Th: InputFirstNameNotExist
        public void ContactFollowFirstNameSurname_InputSurnameNotExist_OutputNull()
        {
            string firstName = "";
            string surname = "avssvd";
            int actual = BO.AContactBO.SearchContact(firstName, surname).Count;
            int expected = 0;
            Assert.AreEqual(actual, expected);

        }
        /// <summary>
        /// Contacts the follow first name surname_ input first name not exist_ output null.
        /// </summary>
        [Test]
        //Th: InputSurNameNotExist
        public void ContactFollowFirstNameSurname_InputFirstNameNotExist_OutputNull()
        {
            string firstName = "adasdasds";
            string surname = "";
            int actual = BO.AContactBO.SearchContact(firstName, surname).Count;
            int expected = 0;
            Assert.AreEqual(actual, expected);

        }
        /// <summary>
        /// Contacts the follow first name surname_ input first name surname not exist_ output null.
        /// </summary>
        [Test]
        //Th: InputFirstNameSurNameNotExist
        public void ContactFollowFirstNameSurname_InputFirstNameSurnameNotExist_OutputNull()
        {
            string firstName = "dadsad";
            string surname = "zadwwin";
            int actual = BO.AContactBO.SearchContact(firstName, surname).Count;
            int expected = 0;
            Assert.AreEqual(actual, expected);

        }
        /// <summary>
        /// Contacts the follow first name surname_ input first name sur name exist_ output contact.
        /// </summary>
        [Test]
        //Th: InputFirstNameSurNameExist
        public void ContactFollowFirstNameSurname_InputFirstNameSurNameExist_OutputContact()
        {
            string firstName = "Lydia";
            string surname = "Marc";
            int actual = BO.AContactBO.SearchContact(firstName, surname).Count;
            int expected = 0;
            Assert.Greater(actual, expected);

        }
       
    }
}
